package com.dk.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dk.data.Result;
import com.dk.em.ConstantEnum;
import com.dk.pojo.TCar;
import com.dk.pojo.TOrder;
import com.dk.service.ITOrderService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author author
 * @since 2021-10-29
 */
@RestController
@RequestMapping("/t-order")
public class TOrderController {

    @Autowired
    private ITOrderService itOrderService;

    @ApiOperation(value = "订单增加操作")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "tOrder",value = "实体类:订单",required = true,paramType = "body",dataTypeClass = TOrder.class)
    })
    @PostMapping("/add")
    public Result add(@RequestBody TOrder tOrder){
        tOrder.setCloseTime(new Date());
        boolean b = itOrderService.save(tOrder);
        if(b){
            return Result.bulid(ConstantEnum.SUCCESS);
        }
        return Result.bulid(ConstantEnum.ERROR);
    }


    @ApiOperation(value = "订单查询(通过用户id查询)")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adminId",value = "用户id",required = true,paramType = "path")
    })
    @GetMapping(value = "/{adminId}")
    public Result getInfoId(@PathVariable("adminId")String adminId){

        QueryWrapper Wrapper = new QueryWrapper<TOrder>();
        Wrapper.like("admin_id", adminId);
        List<TOrder> list = itOrderService.selectList(Wrapper);
        return Result.bulid(ConstantEnum.SUCCESS).setResult(list);
    }



    @ApiOperation(value = "订单信息修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "TOrder",value = "实体类:订单",required = true,paramType = "body",dataTypeClass = TCar.class)
    })
    @PutMapping(value = "/update")
    public Result getInfoId(@RequestBody TOrder tOrder){

        Integer i = itOrderService.updateInfo(tOrder);
        if(i>0){
            return Result.bulid(ConstantEnum.SUCCESS);
        }
        return Result.bulid(ConstantEnum.ERROR);
    }




    @ApiOperation(value = "订单信息状态修改")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "id",required = true,paramType = "path"),
            @ApiImplicitParam(name = "status",value = "状态",required = true,paramType = "path")
    })
    @PutMapping(value = "/{status},{id}")
    public Result deleStatus(@PathVariable("id") Integer id,@PathVariable("status")Integer status){

        Integer i = itOrderService.deleInfo(id,status);
        if(i>0){
            return Result.bulid(ConstantEnum.SUCCESS);
        }

        return Result.bulid(ConstantEnum.ERROR);
    }



}
